import 'package:permission_handler/permission_handler.dart';

class PermissionUtil {
  static Future requestPermission() {
    return [
      Permission.phone,
      Permission.storage,
      Permission.photos,
      Permission.camera,
    //  Permission.accessNotificationPolicy,
    ].request().then((_) {
      if (_[Permission.phone]!.isGranted &&
          _[Permission.storage]!.isGranted &&
          _[Permission.photos]!.isGranted &&
          _[Permission.camera]!.isGranted
      //&&
       //   _[Permission.accessNotificationPolicy]!.isGranted
      ) {
        return PermissionStatus.granted;
      } else {
        return PermissionStatus.denied;
      }
    });
  }

  static Future requestVideoPermission() {
    return [Permission.camera, Permission.microphone].request().then((_) {
      if (_[Permission.camera]!.isGranted &&
          _[Permission.microphone]!.isGranted) {
        return PermissionStatus.granted;
      } else {
        return PermissionStatus.denied;
      }
    });
  }

  static Future requestVoicePermission() {
    return [Permission.microphone, Permission.storage].request().then((_) {
      if (_[Permission.microphone]!.isGranted &&
          _[Permission.storage]!.isGranted) {
        return PermissionStatus.granted;
      } else {
        return PermissionStatus.denied;
      }
    });
  }

  static Future requestPicturePermission() {
    return [Permission.photos, Permission.camera, Permission.storage]
        .request()
        .then((_) {
      if (_[Permission.photos]!.isGranted &&
          _[Permission.camera]!.isGranted &&
          _[Permission.storage]!.isGranted) {
        return PermissionStatus.granted;
      } else {
        return PermissionStatus.denied;
      }
    });
  }

  static Future requestAlumPermission() {
    return [Permission.photos].request().then((_) {
      if (_[Permission.photos]!.isGranted) {
        return PermissionStatus.granted;
      } else {
        return PermissionStatus.denied;
      }
    });
  }

  static Future requestNotifyPermission() {
    return [Permission.notification].request().then((_) {
      if (_[Permission.notification]!.isGranted) {
        return PermissionStatus.granted;
      } else {
        return PermissionStatus.denied;
      }
    });
  }

  static Future requestCameraPermission() {
    return [Permission.camera].request().then((_) {
      if (_[Permission.camera]!.isGranted) {
        return PermissionStatus.granted;
      } else {
        return PermissionStatus.denied;
      }
    });
  }

  //获取定位权限
  static Future requestLocationPermission() {
    return [Permission.location].request().then((_) {
      if (_[Permission.location]!.isGranted) {
        return PermissionStatus.granted;
      } else {
        return PermissionStatus.denied;
      }
    });
  }
}
